Checked checkbox jquery
jQuery also has a checked property that can be used to check if a checkbox is checked or not. Use propery 0th index of the jQuery object. Example: $('#light')[0].checked
// select the element
let light = $('#light');
let output = $('#output');
// add onchange event to checkbox
light.onchange = function() {
if (light[0].checked) {
output.html('The light is on');
} else {
output.html('The light is off');
}
};
Category: Git | Comments: 0